#pragma once
#include "MCommon.h"
#include <QWidget>
#include "ui_MDirTree.h"
#include <QTreeView>
#include <QMenu>
#include <QStandardItemModel>
#include <QMouseEvent>
#include "MDirTreeModel.h"

class MResponseData;
class MDocument;

class MDirTree : public QWidget
{
	Q_OBJECT

public:
	MDirTree(QWidget *parent,MDocument *doc);
	~MDirTree();

	bool setData(const QString& strData);
	void save();
protected:
	void treeViewMenu(const QPoint& pos);
	void createTreeMenu();

	void newDoc();
	void newDir();
	void rename();
	void del();

	void viewDoc();
	void editDoc();

	//void getDirs();

	QString makeDirId();
	void getChildDocIds(QModelIndex parent, std::vector<std::string> &data);

	void timerEvent(QTimerEvent *event);

	void addNode(QJsonArray &arr, QStandardItem *parent);
public:
	QString dirTreeToJson();
	void childToJson(QJsonArray &json, QModelIndex &index);

private slots:
	void treeDoubleClicked(const QModelIndex &index);
	void itemDragMoved(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);


private:
	Ui::QtDirTree ui;
	QTreeView *m_docsTree;
	QMenu *m_floderMenu;
	QMenu *m_docMenu;
	//QStandardItemModel *m_model;
	MDirTreeModel *m_model;
	QModelIndex m_menuSelItem;
	int m_nTimerId;
	bool m_changeFlag;
	QModelIndex m_newDoc;
	MDocument *m_doc;
};
